// $_FILEHEADER_BEGIN ***************************
// 版权声明:Timer
// Copyright © 2015 - Timer All Rights Reserved
// 文件名称: ARCellHelper.m
// 创建日期: 15/12/13
// 创 建 人: 甄鑫
// 文件说明: <#content#>
// $_FILEHEADER_END ******************************


#import "ARCellHelper.h"
#import "ARFriendCell.h"
#import "ARReasonCell.h"
#import "ARSimpleCell.h"
#import "ARTitleCell.h"

@implementation ARCellHelper

+ (NSString *)getCellIdWithType:(AR_CELL_TYPE)type
{
    NSString * cellIdStr = @"";
    switch (type) {
        case AR_CELL_TYPE_TITLE:
        {
            cellIdStr = [ARTitleCell getClassName];
        }break;
        case AR_CELL_TYPE_FRIEDN:
        {
            cellIdStr = [ARFriendCell getClassName];
        }break;
        case AR_CELL_TYPE_REASON:
        {
            cellIdStr = [ARReasonCell getClassName];
        }break;
        case AR_CELL_TYPE_SIMPLE:
        {
            cellIdStr = [ARSimpleCell getClassName];
        }break;
        default:
            break;
    }
    return cellIdStr;
}

+ (UITableViewCell<ARCellProtocol> *)createCellWithType:(AR_CELL_TYPE)type andBaseType:(NSInteger)baseType andPageType:(NSInteger)pageType
{
    UITableViewCell<ARCellProtocol> * cell;
    switch (type) {
        case AR_CELL_TYPE_TITLE:
        {
            cell = [ARTitleCell loadBundleNib];
        }break;
        case AR_CELL_TYPE_FRIEDN:
        {
            cell = [ARFriendCell loadBundleNib];
        }break;
        case AR_CELL_TYPE_REASON:
        {
            cell = [ARReasonCell loadBundleNib];
        }break;
        case AR_CELL_TYPE_SIMPLE:
        {
            cell = [ARSimpleCell loadBundleNib];
            ARSimpleCell<ARCellProtocol> *simpleCell = (ARSimpleCell<ARCellProtocol> *)cell;
            [simpleCell cellType:pageType andBaseType:baseType];
            return simpleCell;
        }break;
        default:
            break;
    }
    return cell;
}

+ (CGFloat)getCellHeightWithType:(AR_CELL_TYPE)type andBaseType:(NSInteger)baseType
{
    CGFloat height = 0;
    switch (type) {
        case AR_CELL_TYPE_TITLE:
        {
            height = 90;
        }break;
        case AR_CELL_TYPE_FRIEDN:
        {
            height = 75;
        }break;
        case AR_CELL_TYPE_REASON:
        {
            height = 60;
        }break;
        case AR_CELL_TYPE_SIMPLE:
        {
            // 通过最后一cell 来补充其他没有变化的视图的高度
            CGFloat regularHeight = (45 + 64);
            CGFloat addHeight = regularHeight * kScreenRatio - regularHeight;
            height = 235 + addHeight;
            if (baseType == 0) {
                height+=75;
            }
        }break;
        default:
            break;
    }
    return height*kScreenRatio;
}

@end

@implementation ARCellModel

- (CGFloat)getCellHeight
{
    CGFloat cellHeight = [ARCellHelper getCellHeightWithType:self.cellType andBaseType:[self.cellBaseType integerValue]];
    return cellHeight;
}

- (NSString *)getCellIdStr
{
    return [ARCellHelper getCellIdWithType:self.cellType];
}

- (UITableViewCell<ARCellProtocol> *)getCellNib
{
    return [ARCellHelper createCellWithType:self.cellType andBaseType:[self.cellBaseType integerValue] andPageType:self.parentVCType];
}
@end

@implementation NSDictionary (ARCellModelDataParse)
-(NSString *)creditamount{
    NSString *rsObj = [NSString stringWithFormat:@"%@", [self objectForKey:@"creditamount"]];
    if(rsObj.isNotEmpty){
        return rsObj;
    }
    return @"";
}
-(NSString *)days{
    NSString *rsObj = [NSString stringWithFormat:@"%@", [self objectForKey:@"days"]];
    if(rsObj.isNotEmpty){
        return rsObj;
    }
    return @"";
}
-(NSString *)hopeamount{
    NSString *rsObj = [NSString stringWithFormat:@"%@", [self objectForKey:@"hopeamount"]];
    if(rsObj.isNotEmpty){
        return rsObj;
    }
    return @"";
}
-(NSString *)hoperate{
    NSString *rsObj = [NSString stringWithFormat:@"%@", [self objectForKey:@"hoperate"]];
    if(rsObj.isNotEmpty){
        return rsObj;
    }
    return @"";
}
-(NSString *)investamount{
    NSString *rsObj = [NSString stringWithFormat:@"%@", [self objectForKey:@"investamount"]];
    if(rsObj.isNotEmpty){
        return rsObj;
    }
    return @"";
}
-(NSString *)investrate{
    NSString *rsObj = [NSString stringWithFormat:@"%@", [self objectForKey:@"investrate"]];
    if(rsObj.isNotEmpty){
        return rsObj;
    }
    return @"";
}
-(NSString *)isborrow{
    NSString *rsObj = [NSString stringWithFormat:@"%@", [self objectForKey:@"isborrow"]];
    if(rsObj.isNotEmpty){
        return rsObj;
    }
    return @"";
}
-(NSString *)fetchLevel{
    NSString *rsObj = [NSString stringWithFormat:@"%@", [self objectForKey:@"level"]];
    if(rsObj.isNotEmpty){
        return rsObj;
    }
    return @"";
}
-(NSString *)localid{
    NSString *rsObj = [NSString stringWithFormat:@"%@", [self objectForKey:@"localid"]];
    if(rsObj.isNotEmpty){
        return rsObj;
    }
    return @"";
}
-(NSString *)priod{
    NSString *rsObj = [NSString stringWithFormat:@"%@", [self objectForKey:@"priod"]];
    if(rsObj.isNotEmpty){
        return rsObj;
    }
    return @"";
}
-(NSString *)remainhour{
    NSString *rsObj = [NSString stringWithFormat:@"%@", [self objectForKey:@"remainhour"]];
    if(rsObj.isNotEmpty){
        return rsObj;
    }
    return @"";
}
-(NSString *)remainminute{
    NSString *rsObj = [NSString stringWithFormat:@"%@", [self objectForKey:@"remainminute"]];
    if(rsObj.isNotEmpty){
        return rsObj;
    }
    return @"";
}
-(NSString *)status{
    NSString *rsObj = [NSString stringWithFormat:@"%@", [self objectForKey:@"status"]];
    if(rsObj.isNotEmpty){
        return rsObj;
    }
    return @"";
}
-(NSString *)summary{
    NSString *rsObj = [NSString stringWithFormat:@"%@", [self objectForKey:@"summary"]];
    if(rsObj.isNotEmpty){
        return rsObj;
    }
    return @"";
}
-(NSString *)fullname{
    NSString *rsObj = [NSString stringWithFormat:@"%@", [self objectForKey:@"fullname"]];
    if(rsObj.isNotEmpty){
        return rsObj;
    }
    return @"";
}
-(NSString *)fetchInvestcount{
    NSString *rsObj = [NSString stringWithFormat:@"%@", [self objectForKey:@"investcount"]];
    if(rsObj.isNotEmpty){
        return rsObj;
    }
    return @"";
}
-(NSString *)fetchInteresttime{
    NSString *rsObj = [NSString stringWithFormat:@"%@", [self objectForKey:@"interesttime"]];
    if(rsObj.isNotEmpty){
        return rsObj;
    }
    return @"";
}
@end
